﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Odyssey.Linq;
using SunTzu.Web;
using System.IO;
using Rea.Web.Models;

namespace Odyssey.Web.Controllers
{
    public class ExhibitorController : FrontBaseController
    {
        public ActionResult Credential()
        {
            BindTopNavigation();
            return View();
        }

        [Login]
        public ActionResult New()
        {
            ViewData.Model = db.form_exhibitors.FirstOrDefault(c => c.AccountId == LoginHelper.CurrentUserId)
                ?? new form_exhibitor();
            return View();
        }

        [Login]
        [HttpPost]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CreateExhibitor(int? id)
        {
            form_exhibitor exhibitor = db.form_exhibitors.FirstOrDefault(c => c.AccountId == LoginHelper.CurrentUserId)
                ?? new form_exhibitor();
            HTMLHelper.BindModel(exhibitor);
            exhibitor.AccountId = LoginHelper.CurrentUserId;
            if (exhibitor.SaveOrUpdate())
            {
                SetMessage("保存成功！");
            }

            return RedirectToAction("New");
        }

        #region old codes
        public ActionResult Register()
        {
            BindTopNavigation();
            ViewBag.Countries = GetTable<tb_country>().OrderBy(item => item.name).ToList();
            return View();
        }

        [HttpPost]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult DoRegister()
        {
            tb_exhibiter exhibiter = new tb_exhibiter();
            HTMLHelper.BindModel(exhibiter);
            exhibiter.SaveOrUpdate();
            return Redirect("/");
        }
        #endregion
        //public ActionResult Demo()
        //{
        //    BindTopNavigation();
        //    return View();
        //}

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult AddCredentialCompany()
        {
            tb_credential_company credential_company = new tb_credential_company();
            HTMLHelper.BindModel(credential_company);
            credential_company.SaveOrUpdate();
            return Json(new { success = true, id = credential_company.Id }, "text/html");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult AddCredential()
        {
            tb_credential credential = new tb_credential();
            HTMLHelper.BindModel(credential);
            credential.SaveOrUpdate();
            return Json(new { success = true, id = credential.Id }, "text/html");
        }
    }
}
